package tony.test.minio.oss

import io.swagger.v3.oas.annotations.Operation
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import tony.core.annotation.EnableTonyBoot
import tony.core.oss.IOssService
import tony.core.utils.ifNullOrBlank
import tony.core.utils.uuid
import tony.minio.oss.autoconfigure.MinIoOssAutoConfiguration

/**
 * TestMinioApp is
 * @author tangli
 * @date 2025/10/09 11:43
 */

fun main(args: Array<String>) {
    runApplication<TestMinioApp>(*args)
}

@EnableTonyBoot(
    [MinIoOssAutoConfiguration::class]
)
@SpringBootApplication
class TestMinioApp

@RestController
class TestMinioController(
    private val minioOssService: IOssService
) {

    @Operation
    @PostMapping("/minio-upload")
    fun upload(part: MultipartFile): String {
        return minioOssService.putObject(
            "${uuid()}.${part.originalFilename.ifNullOrBlank().substringAfterLast('.', "")}",
            part.inputStream,
        )
    }

}
